import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map.Entry;
import java.util.TreeMap;

public class day_06_IO_Test_06 {
    public static void main(String[] args) throws IOException {
         // 对文件中的段落进行排序 ———— 改写
        BufferedReader bufferedReader = new BufferedReader(new FileReader("csb.txt",Charset.forName("UTF-8")));
        String line;
        TreeMap<Integer,String> treeMap = new TreeMap<>();

        // 读取文件内容
        while ((line = bufferedReader.readLine()) != null) {
            String[] arr = line.split("\\.");
            treeMap.put(Integer.parseInt(arr[0]), line);
        }

        bufferedReader.close();

        // 将排序后的内容写入文件
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("result.txt",Charset.forName("UTF-8")));
        for (Entry<Integer,String> entrySet : treeMap.entrySet()) {
            bufferedWriter.write(entrySet.getValue());
            bufferedWriter.newLine();
        };
        bufferedWriter.close();
    }
}
